package org.common.utils.field;

import org.common.utils.tool.StringTool;

import java.util.List;

/**
 * 生成配置
 * @author zhouzhibing
 * @date 2025/8/5
 */
public class GeneratorConfig {

    private GeneratorConfig() {

    }
    /**
     * 生成目录
     */
    private String writePath;
    /**
     * 生成包名
     */
    private String packageName;
    /**
     * 表名
     */
    private String tableName;
    /**
     * 类名
     */
    private String className;
    /**
     * 字段列表
     */
    private List<FieldInfo> fieldList;
    /**
     * 是否是kv配置
     */
    private boolean isKvConfig;
    /**
     * 全路径
     */
    private String allPath;

    public String getWritePath() {
        return writePath;
    }

    public String getPackageName() {
        return packageName;
    }

    public String getTableName() {
        return tableName;
    }

    public String getClassName() {
        return className;
    }

    public List<FieldInfo> getFieldList() {
        return fieldList;
    }

    public String getAllPath() {
        return allPath;
    }

    public boolean isKvConfig() {
        return isKvConfig;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder {
        private final GeneratorConfig generatorConfig = new GeneratorConfig();

        public Builder setWritePath(String writePath) {
            generatorConfig.writePath = writePath;
            return this;
        }

        public Builder setPackageName(String packageName) {
            generatorConfig.packageName = packageName;
            return this;
        }

        public Builder setTableName(String tableName) {
            generatorConfig.tableName = tableName;
            generatorConfig.className = StringTool.toMaxHumpString(tableName);
            return this;
        }

        public Builder setFieldList(List<FieldInfo> fieldList) {
            generatorConfig.fieldList = fieldList;
            return this;
        }

        public Builder setKvConfig(boolean isKvConfig) {
            generatorConfig.isKvConfig = isKvConfig;
            return this;
        }

        public GeneratorConfig build() {
            String packagePath = generatorConfig.packageName.replaceAll("\\.", StringTool.SEPARATOR_ESCAPE);
            String minClassName = StringTool.toMinString(generatorConfig.className);
            generatorConfig.allPath = generatorConfig.writePath + StringTool.SEPARATOR_ESCAPE + packagePath + StringTool.SEPARATOR_ESCAPE + minClassName + StringTool.SEPARATOR_ESCAPE;
            generatorConfig.packageName += "." + minClassName;
            return generatorConfig;
        }
    }

}
